<?php 
class getDirAction extends AdminMasterUploadControl{
	public function execute($request){
		//checking authentication
		$path = $request->getParameter('path', '');
		$max_depth = $request->getParameter('max_depth', 0);
		$str = ($request->isSecure()?'https://':'http://').$_SERVER['HTTP_HOST'].'/admin/uploadControl/directories?directory_path='.$path.'&max_depth='.$max_depth;
		$json_structure = file_get_contents($str);
		$data = json_decode($json_structure,true);
		echo '<ul id="red" class="filetree vi-treeview">';
		foreach($data as $item){
			echo '<li data-path="',$item['path'],'"><span class="folder">',$item['name'],'</span>';
			$this->getItem($item['children']);
			echo '</li>';
		}
		echo '</ul>';
		return sfView::NONE;
	}
	private function getItem($data){
		if(!is_array($data) || count($data)<=0) return;
		echo '<ul>';
		foreach($data as $item){
			echo '<li data-path="',$item['path'],'"><span class="folder">',$item['name'],'</span>';
			$this->getItem($item['children']);
			echo '</li>';
		}
		echo '</ul>';
	}
}